namespace SuppKids.Migrator.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class NewStructure : DbMigration
    {
        public override void Up()
        {
            DropForeignKey("dbo.ProductConsumptions", "Dish_Id", "dbo.Dishes");
            DropForeignKey("dbo.ProductConsumptions", "Product_Id", "dbo.Products");
            DropIndex("dbo.ProductConsumptions", new[] { "Dish_Id" });
            DropIndex("dbo.ProductConsumptions", new[] { "Product_Id" });
            CreateTable(
                "dbo.Ingredients",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Dish_Id = c.Int(),
                        Product_Id = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Dishes", t => t.Dish_Id)
                .ForeignKey("dbo.Products", t => t.Product_Id)
                .Index(t => t.Dish_Id)
                .Index(t => t.Product_Id);
            
            CreateTable(
                "dbo.ProductConsumptionValues",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Group = c.Int(nullable: false),
                        Value = c.Double(nullable: false),
                        Ingredient_Id = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Ingredients", t => t.Ingredient_Id)
                .Index(t => t.Ingredient_Id);
            
            DropTable("dbo.ProductConsumptions");
        }
        
        public override void Down()
        {
            CreateTable(
                "dbo.ProductConsumptions",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Type = c.Int(nullable: false),
                        Value = c.Double(nullable: false),
                        Dish_Id = c.Int(),
                        Product_Id = c.Int(),
                    })
                .PrimaryKey(t => t.Id);
            
            DropForeignKey("dbo.Ingredients", "Product_Id", "dbo.Products");
            DropForeignKey("dbo.Ingredients", "Dish_Id", "dbo.Dishes");
            DropForeignKey("dbo.ProductConsumptionValues", "Ingredient_Id", "dbo.Ingredients");
            DropIndex("dbo.Ingredients", new[] { "Product_Id" });
            DropIndex("dbo.Ingredients", new[] { "Dish_Id" });
            DropIndex("dbo.ProductConsumptionValues", new[] { "Ingredient_Id" });
            DropTable("dbo.ProductConsumptionValues");
            DropTable("dbo.Ingredients");
            CreateIndex("dbo.ProductConsumptions", "Product_Id");
            CreateIndex("dbo.ProductConsumptions", "Dish_Id");
            AddForeignKey("dbo.ProductConsumptions", "Product_Id", "dbo.Products", "Id");
            AddForeignKey("dbo.ProductConsumptions", "Dish_Id", "dbo.Dishes", "Id");
        }
    }
}
